<template>
  <div>
    <!-- 无children -->
    <el-menu-item
      :index="item.path"
      v-for="item in noChildren"
      :key="item.path"
      @click="clickMenu(item)"
    >
    
      <i :class="'iconfont icon-zhankai1'"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <!-- 有children -->
    <el-submenu
      :index="index + ''+itemA.label"
      v-for="(itemA, index) in hasChildren"
      :key="itemA.label + '' + index"
    >
      <template slot="title">
        <i :class="'iconfont icon-zhankai1'"></i>
        <span slot="title">{{ itemA.label }}</span>
      </template>
      <el-menu-item-group>
        <ForMenu :menu="itemA.children"></ForMenu>
      </el-menu-item-group>
    </el-submenu>
  </div>
</template>

<script>
export default {
  name: "ForMenu",
  props: ["menu"],
  data() {
    return {};
  },
  computed: {
    noChildren() {
      return this.menu.filter(item => !item.children);
    },
    hasChildren() {
      return this.menu.filter(item => item.children);
    }
  },
  methods: {
    clickMenu(item) {
      // 设置路由跳转
      // this.$router.push({ name: item.name })
      this.$store.commit("selectMenu", item);
    }
  }
};
</script>

<style lang="scss" scoped>
// 下拉小三角，改为右侧
.el-submenu /deep/.el-icon-arrow-down:before {
    content: "\e6e0"!important;
}
// 展开小三角，改为下側
.el-submenu.is-opened /deep/.el-icon-arrow-down:before {
    content: "\e6e1"!important;
}
.el-menu-item.is-active >span {
  position: relative;
}
// 点击某个菜单item激活后样式
.el-menu-item.is-active >span::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  position: absolute;
  top: 8px;
  left: -15px;
  border-radius: 50%;
  background-color: #EA8A5E;
}

// 二三级菜单选中激活样式
/deep/.el-submenu.is-active> .el-submenu__title{
// background: #26324B!important; // 二级的菜单组
border-right: 0px solid #000!important;
}
// 二三级item激活背景
.el-menu-item.is-active{
background: #26324B!important;
}
</style>